<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Controller;


use AuctionCore\Common\AjaxPage;

class TopicController extends BaseController
{

    private $topicLogic;

    private $empId;

    public function __construct()
    {
        parent::__construct();
        $this->empId = $this->user_info['emp_id'];

        $this->topicLogic = D('Topic', 'Logic');
    }


    public function index()
    {
        $this->display();
    }


    public function topicList()
    {
        $page = I("get.p", 1);
        $size = 10;
        $params = [];
        $params['t_id'] = I('get.t_id/d');
        $params['t_name'] = I('get.t_name', '', 'trim');
        $params['start_time'] = I('get.start_time');
        $params['end_time'] = I('get.end_time');
        $result = $this->topicLogic->getTopicList($page, $size, $params);
//        dump($result);exit;
        $Page = new AjaxPage($result['total'], $size, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %downPage% %nextPage% %end% %jumpform%");
        $show = $Page->show();   // 分页显示输出
        //模板赋值
        $this->assign("p", $page);
        $this->assign('page', $show);   // 赋值分页输出
        $this->assign('list', $result['list']);
        $this->assign('total', $result['total']);
        $this->display();
    }

    public function addTopic()
    {
        $this->display();
    }


    public function addTopicData()
    {
        $data = [];
        $data['topic_name'] = I('post.t_name', '', 'trim');
        if (empty($data['topic_name'])) {
            $this->helpJsonResult(400, '保存失败，未填写专题名称');
        }
        $res = $this->topicLogic->addTopic($data);
        if ($res) {
            $this->helpJsonResult(200, '添加成功');
        } else {
            $this->helpJsonResult(500, '添加失败');
        }
    }

    public function checkTopic()
    {
        $topicId = I('post.t_id/d', 0);
        $topicInfo = D('Topic', 'Logic')->getTopicById($topicId);
        if (empty($topicInfo)) {
            $this->helpJsonResult(400, '抱歉，未查询到专题');
        }
        $this->helpJsonResult(200, '', $topicInfo);
    }


    public function checkCommonQuestion()
    {
        $tid = I('get.tid/d', 0);
        $this->assign('tid', $tid);
        $this->display();
    }

    public function checkPayQuestion()
    {
        $tid = I('get.tid/d', 0);
        $this->assign('tid', $tid);
        $this->display();
    }
}